package com.sgu6.sgu6_machine.ui.fragment.set;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.sgu6.middleware.util.HexUtil;
import com.sgu6.serialport.manager.SerialPortManager;
import com.sgu6.sgu6_machine.R;
import com.sgu6.sgu6_machine.base.BaseF;
import com.sgu6.sgu6_machine.util.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 警报设置
 */
public class HandCommandF extends BaseF {

    @BindView(R.id.etCommand)
    EditText etCommand;
    @BindView(R.id.btnSend)
    Button btnSend;

    public static HandCommandF newInstance() {
        return new HandCommandF();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_hand_command, container, false);
        unbinder = ButterKnife.bind(this, v);

        initUI();
        return v;
    }

    public void initUI() {

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick(R.id.btnSend)
    public void onViewClicked() {
        String command = etCommand.getText().toString().trim();
        Log.i(TAG, "onViewClicked: " + command.length());
        if (command.length() % 2 == 0) {
            SerialPortManager.getInstance().sendBytes(HexUtil.HexString2Bytes(command));
        } else {
            ToastUtil.show(getContext(), "命令长度不对");
        }
    }
}
